/**
 * 
 */
package org.mspring.mlog.web.security.login;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.web.util.AntPathRequestMatcher;
import org.springframework.security.web.util.RequestMatcher;

/**
 * @author Gao Youbo
 * @since 2013-6-8
 * @description
 * @TODO
 */
public class UrlMappingLoginPageStrategy implements LoginPageStrategy {

    /**
     * 在这里判断如何跳转登录页
     */
    @Override
    public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // TODO Auto-generated method stub
        RequestMatcher adminUrlMatcher = new AntPathRequestMatcher("/admin/**");
        RequestMatcher userUrlMatcher = new AntPathRequestMatcher("/u/**");
        if (adminUrlMatcher.matches(request) && !userUrlMatcher.matches(request)) {
            response.sendRedirect(request.getContextPath() + "/admin/login");
        }
        else if (userUrlMatcher.matches(request)) {
            response.sendRedirect(request.getContextPath() + "/u/login");
        }
    }

}
